#include "light_ill.h"
#include "cmsis_os2.h"
#include "ohos_init.h"
#include <stdio.h>

// 传感器数据采集任务
static void *Sensor_TASK(void *arg)
{
    (void)arg; // 避免未使用参数警告
    uint16_t light_value = 0;
    
    while (1) {
        light_value = light_get_data();
        printf("Light Intensity: %d%%\n", light_value);
        osDelay(500); // 500ms采样间隔
    }
    
    return NULL;
}

// 主入口函数
static void MAIN_Entry(void)
{
    // 初始化光照传感器
    light_init();
    printf("Light sensor initialized.\n");
    
    // 创建传感器任务
    osThreadAttr_t attr = {
        .name = "Sensor_TASK",
        .attr_bits = 0U,
        .cb_mem = NULL,
        .cb_size = 0U,
        .stack_mem = NULL,
        .stack_size = 1024 * 5, // 5KB栈空间
        .priority = osPriorityNormal
    };
    
    if (osThreadNew(Sensor_TASK, NULL, &attr) == NULL) {
        printf("Failed to create Sensor_TASK!\n");
    } else {
        printf("Sensor_TASK created successfully.\n");
    }
}

// 注册应用入口
APP_FEATURE_INIT(MAIN_Entry);